package com.bjqg.bjqg01.bjqg.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bjqg.bjqg01.bjqg.R;
import com.bjqg.bjqg01.bjqg.activity.seekprice.bean.PriceAndnameBean;

import java.util.List;

/**
 * Created by gao on 2017/8/3.
 */

public class LeftAdapter extends RecyclerView.Adapter<LeftAdapter.MyViewHolder> {
    private List<PriceAndnameBean> titles;
    private Context context;

    public LeftAdapter(List<PriceAndnameBean> titles, Context context) {
        this.titles = titles;
        this.context = context;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
//        View itemView = LayoutInflater.from(context).inflate(R.layout.item_top, parent, false);
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_top, parent, false);
        return new MyViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        holder.tvname.setText(titles.get(position).getName());
        holder.tvprice.setText("¥" + titles.get(position).getPrice());
        holder.tvnumber.setText(titles.get(position).getNumber());
    }

    @Override
    public int getItemCount() {
        return titles.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        TextView tvname, tvprice, tvnumber;

        public MyViewHolder(View itemView) {
            super(itemView);
            tvname = (TextView) itemView.findViewById(R.id.tv_name);
            tvprice = (TextView) itemView.findViewById(R.id.tv_price);
            tvnumber = (TextView) itemView.findViewById(R.id.tv_number);
        }
    }
}
